package com.tjbklx1.pattern.factory.demo1;

/**
 * 工厂的实现方法
 * 
 * @author tjbklx1
 * @date 2018-10-10
 */
public class HumanFactory extends AbstractHumanFactory {

	@SuppressWarnings("unchecked")
	@Override
	public <T extends Human> T createHuman(Class<T> c) {
		Human human = null;
		try {
			//利用反射创建对象的类
			human = (T) Class.forName(c.getName()).newInstance();
		} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
			System.out.println("create human error.");
			e.printStackTrace();
		}
		return (T) human;
	}
}
